package com.iflytek.controller;

import com.iflytek.common.Result;
import com.iflytek.dto.AddressDTO;
import com.iflytek.dto.PageDTO;
import com.iflytek.service.AddressService;
import com.iflytek.vo.AddressVO;
import com.iflytek.vo.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @author h_t
 * @since 2023-09-23
 */
@RestController
@RequestMapping("/api/address")
public class AddressController{
    @Resource
    public AddressService addressService;

    /**
     * 查询所有地址（非分页）findAll
     * @return
     */
    @ApiOperation("查询全部")
    @GetMapping("")
    Result<List<AddressVO>> findAll() {
        return addressService.findAll();
    }

    /**
     * 保存地址save
     * @param dto
     * @return
     */
    @ApiOperation("保存")
    @PostMapping("")
    Result<Boolean> saveAddress(@RequestBody AddressDTO dto) {
        return addressService.saveAddress(dto);
    }

    /**
     * 更新地址信息update
     * @param dto
     * @return
     */
    @ApiOperation("更新")
    @PutMapping("")
    Result<Boolean> updateAddress(@RequestBody AddressDTO dto) {
        return addressService.updateAddress(dto);
    }

    /**
     * 地址分页查询findPage
     * @param dto
     * @return
     */
    @ApiOperation("分页")
    @GetMapping("/page/front")
    Result<PageVO<AddressVO>> findPage(PageDTO<AddressDTO> dto) {
        return addressService.findPage(dto);
    }


    /**
     * 地址分页查询findById
     * @param id
     * @return
     */
    @ApiOperation("根据id查")
    @PostMapping("/{id}")
    Result<AddressVO> findById(@PathVariable("id") Integer id) {
        return addressService.findById(id);
    }

    /**
     * 根据id删除地址deleteById
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("{id}")
    Result<AddressVO> deleteById(@PathVariable("id") Integer id) {
        return addressService.deleteById(id);
    }

}
